﻿//Created by Action Script Viewer - http://www.buraks.com/asv
package Classes.util {
    import flash.events.*;
    import Engine.Events.*;
    import Engine.Managers.*;
    import flash.utils.*;
    import Transactions.*;

    public class ZyParamsUpdateTracker {

        public static const CHECK_DELAY_MS:int = 60000;
        public static const MAX_DELAY_MS:int = 300000;

        protected static var m_lastTransactionTime:Number;
        protected static var m_timer:Timer;

        public static function initialize():void{
            m_lastTransactionTime = GlobalEngine.getTimer();
            TransactionManager.getInstance().addEventListener(TransactionEvent.ADDED, onTransactionAdded);
            m_timer = new Timer(CHECK_DELAY_MS);
            m_timer.addEventListener(TimerEvent.TIMER, onTimerEvent);
            m_timer.start();
        }
        public static function shutdown():void{
            m_timer.stop();
            m_timer.removeEventListener(TimerEvent.TIMER, onTimerEvent);
            m_timer = null;
            TransactionManager.getInstance().removeEventListener(TransactionEvent.ADDED, onTransactionAdded);
        }
        public static function onTimerEvent(_arg1:TimerEvent):void{
            var _local2:Number = (GlobalEngine.getTimer() - m_lastTransactionTime);
            if (_local2 > MAX_DELAY_MS){
                updateZyParams();
            };
        }
        public static function onTransactionAdded(_arg1:TransactionEvent):void{
            m_lastTransactionTime = GlobalEngine.getTimer();
        }
        protected static function updateZyParams():void{
            GameTransactionManager.addTransaction(new TUpdateEnergy(), true);
        }

    }
}//package Classes.util 
